package com.jiangds.open.check.checker;

import com.jiangds.open.check.Checker;
import com.jiangds.open.exception.CheckExceptionFactory;
import java.util.Map;

/**
 * {@link MapChecker}  Map对象的校验
 *
 * @author jiangliang
 * @since 2021/1/6 12:37
 */
public class MapChecker extends AbstractChecker<Integer, Map> {

    public MapChecker(Map target) {
        super(target);
    }

    @Override
    public Checker<Integer, Map> notEmpty() {
        notNull();
        return processor(t->t.size()>0);
    }

    @Override
    public Checker<Integer, Map> range(Integer min, Integer max) {
        return integerRangeProcessor(Map::size,min,max);
    }

    @Override
    public Checker<Integer, Map> greater(Map greaterThan) {
        return processor(t->t.size() >= greaterThan.size());
    }

    @Override
    public Checker<Integer, Map> less(Map lessThan) {
        return processor(t-> t.size() <= lessThan.size());
    }

    @Override
    public Checker<Integer, Map> in(Map... args) {
        return inProcessor(Map::equals,args);
    }

    @Override
    public Checker<Integer, Map> regex(String regex) {
        throw CheckExceptionFactory.build("Map不支持regex操作");
    }
}
